import Vue from 'vue'
import Router from 'vue-router'



// 导入路由组件

import Upload from '@/views/upload'

import Donate from '@/views/Donate'



// 使用路由
Vue.use(Router)

//设置push方法，避免路由重复切换时报异常
//获取原型对象上的push函数
const originalPush = Router.prototype.push
    //修改原型对象中的push方法
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}


export default new Router({
        // 配置路由
        routes: [{
                path: "/",
                name: "Layout",
                component: () =>
                    import ("@/Layout/layout"),
                redirect: "/user", //重定向跳转
                children: [{
                        //用户管理
                        path: 'user',
                        name: 'User',
                        component: () =>
                            import ("@/views/User"),
                    },
                    { //书籍管理
                        path: 'person',
                        name: 'Person',
                        component: () =>
                            import ("@/views/Person"),
                    },
                    { //分类管理
                        path: 'category',
                        name: 'Category',
                        component: () =>
                            import ("@/views/Category"),
                    },
                    { //书籍管理
                        path: 'book',
                        name: 'Book',
                        component: () =>
                            import ("@/views/Book"),
                    },
                    { //新闻管理
                        path: 'news',
                        name: 'News',
                        component: () =>
                            import ("@/views/News"),
                    },


                ]
            }, {
                path: "/register",
                name: "Register",
                component: () =>
                    import ("@/views/Register"),
            }, {
                path: "/upload",
                name: "Upload",
                component: Upload,
            },
            {
                path: "/login",
                name: "Login",
                component: () =>
                    import ("@/views/Login"),
            },
            {
                path: "/donate",
                name: "Donate",
                component: Donate,
            },



        ],
        // 切换路由方式
        mode: 'history'
    }

)